package com.knav.inject;

import android.app.Activity;

import androidx.appcompat.app.AppCompatActivity;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import static com.knav.inject.LogInject.LogInjectHandle.registerLog;

public class RegisterAppCompatActivityInject {
    private Class<? extends AppCompatActivity> AppCompatActivityInject = AppCompatActivity.class;

    public static RegisterAppCompatActivityInject builder() {


        return new RegisterAppCompatActivityInject();
    }



    private boolean dispatchAppCompatActivity(Activity activity) throws Exception {
        Class<? extends AppCompatActivity> subClass = this.AppCompatActivityInject.asSubclass(AppCompatActivity.class);
        Dispatcher dispatcher = new Dispatcher();
        Field[] fields = subClass.getDeclaredFields();
        Method[] methods = subClass.getMethods();
        dispatcher.dispatcherAppCompatActivity(subClass, activity, fields, methods);
        registerLog(this.AppCompatActivityInject);
        return true;
    }

    public void registerAppCompatActivity(Class<? extends AppCompatActivity> imp, Activity activity) {
        this.AppCompatActivityInject = imp;
        try {
            dispatchAppCompatActivity(activity);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }




}
